package com.cstp.web.res;

import lombok.Data;

/**
 * @author watts
 */
@Data
public class Resp<T> {

    private int code;

    private String msg;

    private T data;

    public static <T> Resp<T> ok() {
        Resp<T> resp = new Resp<>();
        resp.setCode(200);
        resp.setMsg("success");
        return resp;
    }

    public static <T> Resp<T> fail() {
        Resp<T> resp = new Resp<>();
        resp.setCode(-1);
        resp.setMsg("fail");
        return resp;
    }

    public static <T> Resp<T> fail(String msg) {
        Resp<T> resp = new Resp<>();
        resp.setCode(-1);
        resp.setMsg(msg);
        return resp;
    }

    public static <T> Resp<T> fail(int code, String msg) {
        Resp<T> resp = new Resp<>();
        resp.setCode(code);
        resp.setMsg(msg);
        return resp;
    }

    public static <T> Resp<T> ok(T t) {
        Resp<T> resp = new Resp<>();
        resp.setCode(200);
        resp.setMsg("success");
        resp.setData(t);
        return resp;
    }
}
